package com.kingsoft.dc.khaos.plugin.core;

import com.kingsoft.dc.khaos.plugin.core.metadata.PluginModuleConfig;

import java.util.List;

/**
 * Created by jing on 19/7/22.
 */
public class KhaosEnv {
    private Boolean isStopped = false;

    private String id;

    private int priority;

    private List<PluginModuleConfig> dittoInfo;

    private KhaosConf conf;

    private static KhaosEnv env;

    public KhaosEnv(String id, int priority, List<PluginModuleConfig> _dittoInfo, KhaosConf conf) {
        this.id = id;
        this.priority = priority;
        this.dittoInfo = _dittoInfo;
        this.conf = conf;
    }

    public Boolean getStopped() {
        return isStopped;
    }

    public void setStopped(Boolean stopped) {
        isStopped = stopped;
    }

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public int getPriority() {
        return priority;
    }

    public void setPriority(int priority) {
        this.priority = priority;
    }

    public List<PluginModuleConfig> getDittoInfo() {
        return dittoInfo;
    }

    public void setDittoInfo(List<PluginModuleConfig> dittoInfo) {
        this.dittoInfo = dittoInfo;
    }

    public KhaosConf getConf() {
        return conf;
    }

    public void setConf(KhaosConf conf) {
        this.conf = conf;
    }

    public void stop() {
        if (!isStopped) {
            isStopped = true;
        }
    }

    public static KhaosEnv createEnv(String applicationId,
                            KhaosConf conf,
                            List<PluginModuleConfig> khaosInfo) {
        return create(applicationId, conf, khaosInfo);
    }

    private static KhaosEnv create(String applicationId,
                          KhaosConf conf,
                          List<PluginModuleConfig> khaosInfo) {
        String  id = applicationId;
        int priority = conf.getInt("khaos.app.priority", 1);
//        Serializable serializer = null;

        KhaosEnv envInstance = new KhaosEnv(id, priority, khaosInfo, conf);
        return envInstance;
    }

    public static void set(KhaosEnv _env) {
        env = _env;
    }

}
